<template>
  <div class="login_container">
    <div class="login_box">
      <div class="user_img">
        <div class="hehe"><img src="../../assets/img/11.jpeg" /></div>
      </div>
      <el-form ref="loginForm" :model="form" :rules="rules" class="login_form" @keyup.enter.native="logins('loginForm')">
        <el-form-item prop="username">
          <el-input placeholder="用户名/邮箱/手机号" v-model="form.username" prefix-icon="el-icon-user-solid"></el-input>
        </el-form-item>
        <el-form-item prop="password">
          <el-input placeholder="密码" v-model="form.password" :prefix-icon="form.password ? 'el-icon-unlock' : 'el-icon-lock'"></el-input>
        </el-form-item>
        <el-form-item class="login_btn">
          <el-button type="primary" @click="logins('loginForm')">登陆</el-button>
          <el-button type="info" @click="resetForm('loginForm')">重置</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      form: {
        username: 'admin',
        password: '123456'
      },
      rules: {
        username: [
          { required: true, message: '请输入名字', trigger: 'blur' },
          { min: 3, max: 11, message: '长度在 3 到 11 个字符', trigger: 'blur' }
        ],
        password: [
          { required: true, message: '请输入密码', trigger: 'blur' },
          { min: 6, max: 16, message: '长度在 6 到 16 个字符', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    resetForm(val) {
      this.$refs[val].resetFields()
    },
    logins(val) {
      this.$refs[val].validate(async resopen => {
        // let { data: res } = await this.$axios.post('login', this.form)
        // if (res.meta.status !== 200) {
        //   this.$message.error(res.meta.msg)
        //   return
        // }
        // this.$message({
        //   message: res.meta.msg,
        //   type: 'success'
        // })
        // window.sessionStorage.setItem('token', res.data.token)
        // this.$router.push('/home')
        if (this.form.username === 'admin' && this.form.password === '123456') {
          window.localStorage.setItem('token', 'qwerty')
          this.$router.push('/home')
        }
      })
    }
  }
}
</script>

<style lang="less" socped>
.login_container {
  background-color: #eee6f0;
  .login_box {
    width: 500px;
    height: 330px;
    background: #fff;
    border-radius: 6px;
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    .user_img {
      border-radius: 50%;
      width: 180px;
      height: 180px;
      box-shadow: 0 0 4px;
      position: absolute;
      left: 50%;
      transform: translate(-50%, -50%);
      box-sizing: border-box;
      .hehe {
        background: #fff;
        border-radius: 50%;
        box-sizing: border-box;
        padding: 10px;
        width: 100%;
        height: 100%;
        img {
          width: 100%;
          height: 100%;
          border-radius: 50%;
        }
      }
    }
  }

  .login_form {
    position: absolute;
    bottom: 5px;
    width: 100%;
    height: 70%;
    padding: 20px;
    box-sizing: border-box;
  }
  .login_btn {
    margin-top: 40px;
    display: flex;
    justify-content: flex-end;
  }
}
</style>
